package com.xgst.land.activity

import android.content.Intent
import android.graphics.Color
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.SPStaticUtils
import com.blankj.utilcode.util.SpanUtils
import com.blankj.utilcode.util.TimeUtils
import com.githang.statusbar.StatusBarCompat
import com.gym.baselib.base.BaseActivity
import com.ht.medicaltreatment.base.CacheKey
import com.ht.medicaltreatment.serial.SerialPortUtils
import com.xgst.land.R
import com.xgst.land.activity.check.InventoryOrderListActivity
import com.xgst.land.activity.check.InventoryScanLandActivity
import com.xgst.land.databinding.ActivityMainBinding
import com.xgst.land.utils.WeekDayUtils
import java.text.SimpleDateFormat

class MainActivity : BaseActivity<ActivityMainBinding>(), View.OnClickListener {

    override fun viewBinding() = ActivityMainBinding.inflate(layoutInflater)

    override fun init() {
        StatusBarCompat.setStatusBarColor(this, getColor(R.color.blue))
        binding.tvName.text = SPStaticUtils.getString(CacheKey.NAME, "--")
        binding.imgCheck.setOnClickListener(this)
        binding.imgGuide.setOnClickListener(this)
        binding.imgIn.setOnClickListener(this)

        binding.tvTitle.text = "${TimeUtils.getNowString(SimpleDateFormat("MM"))}月"
        WeekDayUtils.getWeekDayList { list, weekNumber ->
            list.forEachIndexed { index, mill ->
                val linearLayout = binding.llWeek.getChildAt(index) as LinearLayout
                val date = TimeUtils.millis2String(mill, SimpleDateFormat("dd"))
                val week = TimeUtils.getChineseWeek(mill)

                val weekText = linearLayout.getChildAt(0) as TextView
                weekText.setText(week)
                val dateText = linearLayout.getChildAt(1) as TextView
                dateText.setText(date)

                if (weekNumber == 1 && index == 6) {
                    linearLayout.setBackgroundResource(R.drawable.shape_juxing_bg_white)
                    weekText.setTextColor(getColor(R.color.blue))
                    dateText.setTextColor(getColor(R.color.blue))
                } else if (weekNumber - 2 == index) {
                    linearLayout.setBackgroundResource(R.drawable.shape_juxing_bg_white)
                    weekText.setTextColor(getColor(R.color.blue))
                    dateText.setTextColor(getColor(R.color.blue))
                }
            }
        }
        SerialPortUtils.initDevice()
    }

    override fun onClick(view: View?) {
        when (view) {
            //盘点
            binding.imgCheck -> ActivityUtils.startActivity(InventoryOrderListActivity::class.java)
            binding.imgGuide -> {
                var intent = Intent(this, InventoryScanLandActivity::class.java)
                intent.putExtra("uid", "E0040150A944AF6C") //
                intent.putExtra("orderId", 3)
                startActivity(intent)
            }
            //转出
            binding.imgIn -> {

            }
        }
    }

}